package com.itheima.servlet;

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.Keyword;
import com.itheima.service.KeywordService;
import com.itheima.service.impl.KeywrodServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/KeyWordServlet")
public class KeyWordServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String value = request.getParameter("v");
        KeywordService keywordService = new KeywrodServiceImpl();
        List<Keyword> keywords = keywordService.find(value);
        response.setContentType("text/html;charset=utf-8");
        String s = JSON.toJSONString(keywords);
        response.getWriter().print(s);

    }
}
